﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKB.Common;
using HKB.Web.Admin;

public partial class Admin_admin_adminpassword : Admin, IRequiresSessionState
{
    private int AdminID = 0;
    private AdminBll _adminbll = null;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected AdminBll m_adminbll
    {
        get
        {
            AdminBll adminbll;
            if (this._adminbll == null)
            {
                this._adminbll = new AdminBll(this.conn);
                adminbll = this._adminbll;
            }
            else
            {
                adminbll = this._adminbll;
            }
            return adminbll;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.AdminID = Fetch.GetID("Admin_ID");
        if (this.AdminID > 0)
        {
            if (!base.admin.CheckSuperAdmin())
            {
                this.WriteErrMsg("", "只有超级管理员才有权修改他人密码！", "");
            }
            DataTable adminByAdminID = this.m_adminbll.GetAdminByAdminID(this.AdminID);
            if (adminByAdminID.Rows.Count == 1)
            {
                this.AdminName.Text = adminByAdminID.Rows[0]["UserName"].ToString();
            }
            else
            {
                this.WriteErrMsg("", "找不到该管理员帐号！", "");
            }
        }
        else
        {
            this.AdminID = base.admin.AdminID;
            this.AdminName.Text = base.admin.AdminName;
        }
    }
    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        if (this.PassWord1.Text == this.PassWord2.Text)
        {
            string newPassWord = this.HTMLEncode(this.PassWord1.Text);
            string oldPassWord = this.HTMLEncode(this.OldPassword.Text);
            int num = this.m_adminbll.ChangePassword(this.AdminID, oldPassWord, newPassWord);
            if (num == 0)
            {
                this.WriteSuccessMsg("", "修改密码成功！", "");
            }
            else
            {
                if (num == 1)
                {
                    this.WriteErrMsg("", "管理员不存在，修改密码不成功！", "");
                }
                else
                {
                    if (num == 2)
                    {
                        this.WriteErrMsg("", "旧密码不正确，修改密码不成功！", "");
                    }
                    else
                    {
                        this.WriteErrMsg("", "修改密码不成功，未知错误！", "");
                    }
                }
            }
        }
        else
        {
            this.WriteErrMsg("", "两次输入新密码不相同，请重新再输入!", "");
        }
    }
}